<!--
 * @author hemengxia
 企业账号管理-交易记录
-->
<template>
  <section class="transaction-record">
    <section class="main-search">
      <div class="search-label">交易时间</div>
      <el-row :gutter="10">
        <el-col :span="18">
          <section class="search-item">
            <el-date-picker
                v-model="search.time"
                range-separator="至"
                start-placeholder="交易开始时间"
                end-placeholder="交易结束时间"
                clearable
                :style="{width:'100%'}"
                type="daterange"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']"
            />
          </section>

        </el-col>
        <el-col :span="6">

          <section class="search-item" style="text-align: center;">

            <el-button type="primary" @click="handleFilter">搜索</el-button>
            <el-button type="primary" @click="handleReset">重置</el-button>
          </section>
        </el-col>
      </el-row>
    </section>

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>交易记录</span>
      </section>
      <section class="main-buttons-btns">
        <el-button class="filter-item" style="margin-left: 10px;" @click="handleExport">导出</el-button>
        <el-button style="padding: 10px 30px;" @click="handleCancel()">返回</el-button>
      </section>
    </section>
    <section class="main-table">
      <v-table
        :list="list"
        tag="transactionRecord"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
        :selection="false"
      >
<!--        <el-table-column label="操作" fixed="right" align="center" min-width="100" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>-->
      </v-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
        :page-sizes="[ 100,]"
      />
    </section>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import { queryRecord } from '../api'
import permission from '@/directive/permission/index.js'

export default {
  name: 'TransactionRecord',
  components: { Pagination, VTable },
  directives: { permission },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 100,
        userRealname: ''
      },
      searchshow: true,
      search: {
        userRealname: '',
        deptName: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      dict: {
        'HBHDLQZT': [],
        'HBHDGQZT': []
      },
      view: '/API-DOCUMENT/document/file/download?id=',
      link: '/survey?i=',
      previewStatus: false,
      obj: {},
      id: ''
    }
  },
  created() {
    this.id = this.$route.query.i
    /*  for (const i in this.dict) {
        this.getDict(i)
      }*/
    this.getList()
  },
  methods: {
    /**
     * 导出
     * @param row
     */
    handleExport() {
      this.$router.push({ path: this.$filterPath('statistics'), query: { i: this.id } })
    },
    handleCancel() {
      this.$router.back()
    },


    filtercolumn(scope, item) {
      if (item === 'coverImgId') {
        return this.view + scope.row[item]
      } else {
        return scope.row[item]
      }
    },

    handleReset() {
      this.listQuery.page = 1
      this.listQuery.userRealname = ''
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        accountId: this.id
      }
      query['startDate'] = this.search.time && this.search.time.length > 0 ? this.search.time[0] : ''
      query['endDate'] = this.search.time && this.search.time.length > 0 ? this.search.time[1] : ''
      return new Promise((resolve, reject) => {
        queryRecord(query).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }

  }
}
</script>
<style lang="scss">

.transaction-record {
  padding:  10px;

  .main-search {
    background-color: #fff;
    padding: 10px;
    .search-label{
      height: 30px;
      line-height: 30px;
      font-size: 14px;
      color: #a6a6a6;
      font-weight: 400;
    }
    .search-item {
      margin-bottom: 10px;
      &.button {
        text-align: center;
      }
      .item-label {
        height: 30px;
        line-height: 30px;
        font-size: 14px;
        color: #a6a6a6;
        font-weight: 400;
      }

      .el-input {
        position: relative;

        &.el-date-editor input {
          padding-left: 30px;
        }

        .el-input__inner {
          border: none;
          padding: 0;
        }

        &:after {
          content: '';
          height: 1px;
          background-color: #e2e3e8;
          position: absolute;
          left: 0;
          right: 0;
          bottom: 0;
        }
      }
    }
  }

  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-top: 10px;

    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }
}
</style>
